package jxta.chat;

import jxta.chat.entities.AbstractMessage;
import jxta.chat.entities.MessageFactory;
import jxta.chat.events.JxtaChatEvent;
import jxta.chat.util.Constants;
import net.jxta.endpoint.Message;
import net.jxta.endpoint.MessageElement;
import net.jxta.peergroup.PeerGroup;
import net.jxta.pipe.PipeMsgEvent;

/**
 * A class that handles regular messages
 */
public class RegularMessageHandler extends AbstractMessageHandler{

	@Override
	public AbstractMessage handleMessage(Message msg, PeerGroup pg) {
		
		JxtaChatEvent event = null;
		
		MessageElement msgElement = msg.getMessageElement(null, Constants.MESSAGE_NAME_SPACE);
		AbstractMessage msgClass = MessageFactory.getInstance().getMessageClass(msg);
		
		JxtaChatEvent msgEvent = new JxtaChatEvent(msgClass, msgElement.toString());    			
		notifyListeners(msgEvent);
		
		return null;
	}

	public void pipeMsgEvent(PipeMsgEvent event) {
		// TODO Auto-generated method stub
		
	}
}
